package com.akk.platform.oem;

import com.akk.module.avs.entity.*;
import com.akk.module.avs.model.request.*;
import com.akk.platform.oem.business.*;
import com.akk.utils.Query;
import com.akk.utils.RestResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping(value = "/platform/oem")
@Api(value = "御贝增值",description = "御贝增值Api接口")
public class YbIncreAction {

    @Autowired
    private YbLoanTypeBusiness typeBusiness;

    @Autowired
    private YbLoanBusiness loanBusiness;

    @Autowired
    private YbLoanRecordBusiness recordBusiness;

    @Autowired
    private YbCardTagTypeBusiness cardTagTypeBusiness;

    @Autowired
    private YbAppoCardBusiness appoCardBusiness;

    @Autowired
    private YbCardBuiness cardBuiness;

    @Autowired
    private YbCardAccessBusiness cardAccessBusiness;

    @Autowired
    private YbCardRaiderBusiness cardRaiderBusiness;

    @Autowired
    private YbLoanAccessBusiness loanAccessBusiness;

    @Autowired
    private YbInfoBusiness infoBusiness;

    @Autowired
    private YbBankBusiness bankBusiness;

    @Autowired
    private YbStepBusiness stepBusiness;

    @ApiOperation(value = "贷款类型列表",httpMethod = "GET",response = RestResponse.class)
    @RequestMapping(value = "/typelist")
    public RestResponse typeList(Query query){
        return typeBusiness.list(query);
    }

    @ApiOperation(value = "获取类型信息",httpMethod = "GET",response = RestResponse.class)
    @RequestMapping(value = "/typeinfo/{typeId}")
    public RestResponse typeInfo(@PathVariable Long typeId){
        return typeBusiness.info(typeId);
    }

    @ApiOperation(value = "添加贷款类型",httpMethod = "POST",response = RestResponse.class)
    @PostMapping(value = "/typeadd")
    public RestResponse typeAdd(@Valid AvsYbLoanTypeReq req, BindingResult bindingResult){
        return typeBusiness.save(req,bindingResult);
    }

    @ApiOperation(value = "删除贷款类型",httpMethod = "GET",response = RestResponse.class)
    @GetMapping(value = "/typedel/{typeId}")
    public RestResponse typeDel(@PathVariable Long typeId){
        return typeBusiness.delete(typeId);
    }

    @ApiOperation(value = "修改类型",httpMethod = "POST",response = RestResponse.class)
    @PostMapping(value = "/typeupdate")
    public RestResponse typeUpdate(AvsYbLoanTypeReq req){
        return typeBusiness.update(req);
    }

    @ApiOperation(value = "贷款列表",httpMethod = "GET",response = RestResponse.class)
    @GetMapping(value = "/loanlist")
    public RestResponse loanList(@Valid Query query,BindingResult bindingResult){
        return loanBusiness.list(query,bindingResult);
    }

    @ApiOperation(value = "贷款信息",httpMethod = "GET",response = RestResponse.class)
    @GetMapping(value = "/loaninfo/{loanId}")
    public RestResponse loanInfo(@PathVariable Long loanId){
        return loanBusiness.info(loanId);
    }

    @ApiOperation(value = "添加贷款",httpMethod = "POST",response = RestResponse.class)
    @PostMapping(value = "/loanadd")
    public RestResponse loanAdd(@RequestBody AvsYbLoanRequest loan){
        return loanBusiness.save(loan);
    }

    @ApiOperation(value = "修改贷款",httpMethod = "POST",response = RestResponse.class)
    @PostMapping(value = "/loanupdate")
    public RestResponse update(@RequestBody AvsYbLoanRequest loan){
        return loanBusiness.update(loan);
    }

    @ApiOperation(value = "删除贷款",httpMethod = "GET",response = RestResponse.class)
    @GetMapping(value = "/loandel/{loanId}")
    public RestResponse loanDel(@PathVariable Long loanId){
        return loanBusiness.del(loanId);
    }

    @ApiOperation(value = "贷款记录列表",httpMethod = "GET",response = RestResponse.class)
    @GetMapping(value = "/recordlist")
    public RestResponse recordList(@Valid Query query,BindingResult bindingResult){
        return recordBusiness.list(query, bindingResult);
    }

    @ApiOperation(value = "贷款记录信息",httpMethod = "GET",response = RestResponse.class)
    @GetMapping(value = "/recordinfo/{recordId}")
    public RestResponse recordInfo(@PathVariable Long recordId){
        return recordBusiness.recordInfo(recordId);
    }

    @ApiOperation(value = "贷款记录信息",httpMethod = "GET",response = RestResponse.class)
    @GetMapping(value = "/userinfo/{userId}")
    public RestResponse userInfo(@PathVariable Long userId){
        return recordBusiness.userInfo(userId);
    }

    @ApiOperation(value = "处理贷款申请记录",httpMethod = "POST",response = RestResponse.class)
    @PostMapping(value = "/handelrecord")
    public RestResponse handleRecord(@RequestBody AvsYbLoanRecord record){
        return recordBusiness.handelRecord(record);
    }

    @ApiOperation(value = "信用卡标签类型列表",httpMethod = "GET",response = RestResponse.class)
    @GetMapping(value = "/cardTagTypes")
    public RestResponse cardTagType(@Valid Query query,BindingResult bindingResult){
        return cardTagTypeBusiness.list(query,bindingResult);
    }

    @ApiOperation(value = "添加信用卡标签类型",httpMethod = "POST",response = RestResponse.class)
    @PostMapping(value = "/addCardTagType")
    public RestResponse addCardTagType(@RequestBody @Valid AvsYbTagType tagType, BindingResult bindingResult){
        return cardTagTypeBusiness.save(tagType, bindingResult);
    }

    @ApiOperation(value = "删除信用卡标签类型",httpMethod = "GET",response = RestResponse.class)
    @GetMapping(value = "/delCardTagType/{typeId}")
    public RestResponse delCardTagType(@PathVariable Long typeId){
        return cardTagTypeBusiness.del(typeId);
    }

    @ApiOperation(value = "信用卡标签列表",httpMethod = "GET",response = RestResponse.class)
    @GetMapping(value = "/cardTags")
    public RestResponse cardTag(@Valid Query query,BindingResult bindingResult){
        return cardTagTypeBusiness.tagsList(query,bindingResult);
    }

    @ApiOperation(value = "添加信用卡标签",httpMethod = "POST",response = RestResponse.class)
    @PostMapping(value = "/addCardTag")
    public RestResponse addCardTagType(@RequestBody @Valid AvsYbTags tags, BindingResult bindingResult){
        return cardTagTypeBusiness.tagsSave(tags, bindingResult);
    }

    @ApiOperation(value = "删除信用卡标签",httpMethod = "GET",response = RestResponse.class)
    @GetMapping(value = "/delCardTag/{tagId}")
    public RestResponse delCardTag(@PathVariable Long tagId){
        return cardTagTypeBusiness.tagsDel(tagId);
    }

    @ApiOperation(value = "获取所有标签类型",httpMethod = "GET",response = RestResponse.class)
    @GetMapping(value = "/allTagTypes")
    public RestResponse allTagTypes(){
        return cardTagTypeBusiness.allTagTypes();
    }

    @ApiOperation(value = "预约办卡申请列表",httpMethod = "GET",response = RestResponse.class)
    @GetMapping(value = "/appoList")
    public RestResponse appoList(@Valid Query query,BindingResult bindingResult){
        return appoCardBusiness.list(query, bindingResult);
    }

    @ApiOperation(value = "修改预约办卡状态",httpMethod = "POST",response = RestResponse.class)
    @PostMapping(value = "/appoUpdate")
    public RestResponse appoUpdate(@RequestBody AvsYbAppoCard appoCard){
        return appoCardBusiness.update(appoCard);
    }

    @ApiOperation(value = "信用卡列表",httpMethod = "GET",response = RestResponse.class)
    @GetMapping(value = "/cardList")
    public RestResponse cardList(@Valid Query query,BindingResult bindingResult){
        return cardBuiness.list(query,bindingResult);
    }

    @ApiOperation(value = "添加信用卡",httpMethod = "POST",response = RestResponse.class)
    @PostMapping(value = "/addCard")
    public RestResponse addCard(@Valid AvsYbCardRequest request, BindingResult bindingResult){
        return cardBuiness.save(request,bindingResult);
    }

    @ApiOperation(value = "删除信用卡",httpMethod = "GET",response = RestResponse.class)
    @GetMapping(value = "/delCard/{cardId}")
    public RestResponse delCard(@PathVariable Long cardId){
        return cardBuiness.del(cardId);
    }

    @ApiOperation(value = "修改信用卡",httpMethod = "POST",response = RestResponse.class)
    @PostMapping(value = "/updateCard")
    public RestResponse updateCard(@Valid AvsYbCardRequest request,BindingResult bindingResult){
        return cardBuiness.update(request,bindingResult);
    }

    @ApiOperation(value = "信用卡信息",httpMethod = "GET",response = RestResponse.class)
    @GetMapping(value = "/cardInfo/{cardId}")
    public RestResponse cardInfo(@PathVariable Long cardId){
        return cardBuiness.info(cardId);
    }

    @ApiOperation(value = "所有信用卡标签",httpMethod = "GET",response = RestResponse.class)
    @GetMapping(value = "/cardAllTags")
    public RestResponse cardTags(){
        return cardTagTypeBusiness.allTags();
    }

    @ApiOperation(value = "获取信用卡标签",httpMethod = "GET",response = RestResponse.class)
    @GetMapping(value = "/cardTag/{cardId}")
    public RestResponse cardTag(@PathVariable Long cardId){
        return cardTagTypeBusiness.cardTags(cardId);
    }

    @ApiOperation(value = "获取信用卡攻略列表",httpMethod = "GET",response = RestResponse.class)
    @GetMapping(value = "/cardRaiderList")
    public RestResponse cardRaiderList(@Valid Query query,BindingResult bindingResult){
        return cardRaiderBusiness.list(query, bindingResult);
    }

    @ApiOperation(value = "添加信用卡攻略",httpMethod = "POST",response = RestResponse.class)
    @PostMapping(value = "/addCardRaider")
    public RestResponse cardRaiderList( @Valid AvsYbCardRaiderRequest request, BindingResult bindingResult){
        return cardRaiderBusiness.save(request, bindingResult);
    }

    @ApiOperation(value = "删除信用卡攻略",httpMethod = "GET",response = RestResponse.class)
    @GetMapping(value = "/delCardRaider/{raiderId}")
    public RestResponse cardRaiderList(@PathVariable Long raiderId){
        return cardRaiderBusiness.del(raiderId);
    }

    @ApiOperation(value = "获取办卡评估列表",httpMethod = "GET",response = RestResponse.class)
    @GetMapping(value = "/cardAccessList")
    public RestResponse cardAccessList(@Valid Query query,BindingResult bindingResult){
        return cardAccessBusiness.list(query, bindingResult);
    }

    @ApiOperation(value = "获取办卡评估信息",httpMethod = "GET",response = RestResponse.class)
    @GetMapping(value = "/cardAccessInfo/{accessId}")
    public RestResponse cardAccessInfo(@PathVariable Long accessId){
        return cardAccessBusiness.info(accessId);
    }

    @ApiOperation(value = "处理办卡评估",httpMethod = "GET",response = RestResponse.class)
    @GetMapping(value = "/handelCardAccess/{accessId}")
    public RestResponse handelCardAccess(@PathVariable Long accessId){
        return cardAccessBusiness.handel(accessId);
    }


    @GetMapping(value = "/loanAccessList")
    public RestResponse loanAccessList(@Valid Query query,BindingResult bindingResult){
        return loanAccessBusiness.list(query, bindingResult);
    }

    @GetMapping(value = "/loanAccessInfo/{accessId}")
    public RestResponse loanAccessInfo(@PathVariable Long accessId){
        return loanAccessBusiness.info(accessId);
    }

    @GetMapping(value = "/handelLoanAccess/{accessId}")
    public RestResponse handelLoanAccess(@PathVariable Long accessId){
        return loanAccessBusiness.handel(accessId);
    }

    @GetMapping(value = "/info")
    public RestResponse info(){
        return infoBusiness.queryByAppId();
    }

    @PostMapping(value = "/updateInfo")
    @RequiresPermissions("oem:yb:info:update")
    public RestResponse updateInfo(@RequestBody @Valid AvsYbInfo info,BindingResult bindingResult){
        return infoBusiness.update(info,bindingResult);
    }

    @GetMapping(value = "/bankList")
    public RestResponse bankList(@Valid Query query,BindingResult bindingResult){
        return bankBusiness.list(query, bindingResult);
    }

    @GetMapping(value = "/bankDel/{bankId}")
    @RequiresPermissions("oem:yb:bank:del")
    public RestResponse bankDel(@PathVariable Long bankId){
        return bankBusiness.del(bankId);
    }

    @PostMapping(value = "/bankAdd")
    @RequiresPermissions("oem:yb:bank:save")
    public RestResponse bankAdd(@Valid AvsYbBankRequest request,BindingResult bindingResult){
        return bankBusiness.save(request, bindingResult);
    }

    @GetMapping(value = "/stepList")
    @RequiresPermissions("platform:oem:step:list")
    public RestResponse stepList(@Valid Query query,BindingResult bindingResult){
        return stepBusiness.list(query,bindingResult);
    }

    @GetMapping(value = "/stepDel/{stepId}")
    @RequiresPermissions("platform:oem:step:del")
    public RestResponse stepDel(@PathVariable Long stepId){
        return stepBusiness.del(stepId);
    }

    @PostMapping(value = "/stepAdd")
    @RequiresPermissions("platform:oem:step:save")
    public RestResponse stepSave(@Valid AvsYbStepRequest request,BindingResult bindingResult){
        return stepBusiness.save(request, bindingResult);
    }
    @GetMapping(value = "/steps")
    @RequiresPermissions("platform:oem:step:all")
    public RestResponse steps(){
        return stepBusiness.stepAll();
    }

}
